using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using Newtonsoft.Json;
using System;
using UnityEngine.EventSystems;

public class Job1ShopItem : MonoBehaviour, IPointerClickHandler
{
    public TMP_Text ShoplItemUpText1, ShoplItemUpText2, NameText, MoneyText, MoneyTextNew;
    public Image ShoplItemUpImage1, ShoplItemUpImage2, Icon, BjIcon, breakImage, BuyBjIcon, BuyIcon;
    public ShopData My_shopData;
    Job1ShopView My_ShopView;
    internal void init(ShopData shopData, Job1ShopView job1ShopView)
    {
        My_shopData = shopData;
        My_ShopView = job1ShopView;
        ShoplItemUpText2.text = "可兑换:" + shopData.quantity + "/" + shopData.max_quantity;
        ShoplItemUpText1.text = "◷18天12小时";
        ShoplItemUpImage1.gameObject.SetActive(true);
        Icon.sprite = Resources.Load<Sprite>(shopData.icon);
        GetComponent<Image>().sprite = Resources.Load<Sprite>(GetMyIcon(shopData.Level));
        NameText.text = shopData.name;
        MoneyText.text = shopData.price.ToString();
        switch (shopData.discount)
        {
            case discount.兑换:
                MoneyTextNew.gameObject.SetActive(false);
                breakImage.gameObject.SetActive(false);
                break;
            case discount.折扣:
                MoneyTextNew.gameObject.SetActive(true);
                MoneyTextNew.text = (shopData.price * 2f).ToString();
                breakImage.gameObject.SetActive(true);
                break;
        }
        switch (shopData.BuyState)
        {
            case butType.可以购买:
                BuyIcon.gameObject.SetActive(false);
                BuyBjIcon.gameObject.SetActive(false);
                break;
            case butType.售空:
                BuyIcon.gameObject.SetActive(false);
                BuyBjIcon.gameObject.SetActive(true);
                break;
            case butType.暂未开放:
                BuyIcon.gameObject.SetActive(true);
                BuyBjIcon.gameObject.SetActive(true);
                break;
        }
    }
    // Start is called before the first frame update
    void Start()
    {



    }

    // Update is called once per frame
    void Update()
    {

    }
    public string GetMyIcon(int leven)
    {
        switch (leven)
        {
            case 1:
                return "资源切图/白色-底板";
            case 2:
                return "资源切图/绿色-底板";
            case 3:
                return "资源切图/蓝色-底板";
            case 4:
                return "资源切图/紫色-底板";
            case 5:
                return "资源切图/金色-底板";
            default:
                return "";
        }
    }

    internal void SetBg(bool v)
    {
        BjIcon.gameObject.SetActive(v);
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        if (My_shopData.BuyState!= butType.暂未开放)
        {
           My_ShopView.SetItem(this);
        }
    }
}
